package com.example.demo.controller.voj;

import com.example.demo.common.IdParam;
import com.example.demo.domain.entity.VojProblemTags;
import com.example.demo.dto.ProblemCategoryDto;
import com.example.demo.dto.ResponseDto;
import com.example.demo.param.voj.VojCategorySaveParam;
import com.example.demo.param.voj.VojTagSaveParam;
import com.example.demo.service.VojProblemCategoriesService;
import com.example.demo.service.VojProblemTagsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题库模块-试题标签
 */
@Controller
@RequestMapping("/tag")
public class ProblemTagController {

    // TODO  submission && records && rank

    private static final Logger log = LoggerFactory.getLogger(ProblemTagController.class);
    @Resource
    private VojProblemTagsService vojProblemTagsService;

    /**
     * 查询试题标签.
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResponseDto<List<VojProblemTags>> list() {
        List<VojProblemTags> list = vojProblemTagsService.list();
        ResponseDto result = new ResponseDto().buildSucceed();
        result.setContent(list);
        return result;
    }

    /**
     * 创建、保存试题标签
     * @return
     */
    @RequestMapping(value="/save", method= RequestMethod.POST)
    @ResponseBody
    public ResponseDto save(@RequestBody VojTagSaveParam param) {
        vojProblemTagsService.save(param);
        ResponseDto responseDto = new ResponseDto<>().buildSucceed();
        return responseDto;
    }


    /**
     * 删除试题标签.
     * @return
     */
    @RequestMapping(value="/delete", method=RequestMethod.POST)
    @ResponseBody
    public ResponseDto delete(@RequestBody IdParam param) {
        vojProblemTagsService.removeById(param.getId());
        ResponseDto responseDto = new ResponseDto<>().buildSucceed();
        return responseDto;
    }
}
